package com.otojob.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author: TingFeng
 * @CreateTime: 2022/3/17  21:20
 */
//统一返回结果
@Data
public class Results {
    //成功
    private boolean success;
    //返回码
    private Integer code;
    //信息
    private String message;
    //返回map
    private Map<String,Object> data = new HashMap<>();

    private Results(){

    }

    public static Results ok(){
        Results r = new Results();
        r.setSuccess(true);
        r.setCode(5000001);
        r.setMessage("成功");
        return r;
    }
    //失败静态方法

    public static Results error() {
        Results r = new Results();
        r.setSuccess(false);
        r.setCode(500000);
        r.setMessage("失败");
        return r;
    }

    public Results success(Boolean success){
        this.setSuccess(success);
        return this;
    }



    public Results code(Integer code){
        this.setCode(code);
        return this;
    }

    public Results message(String message){
        this.setMessage(message);
        return this;
    }

    public Results data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public Results data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

}
